﻿CREATE VIEW [dbo].[vwParliaments]
AS
SELECT     ParliamentNumber, MIN(DateFrom) AS DateFrom,
                          (SELECT     MIN(DateFrom) AS Expr1
                            FROM          dbo.ParliamentSessions
                            WHERE      (ParliamentNumber = S.ParliamentNumber + 1)) - 1 AS DateTo
FROM         dbo.ParliamentSessions AS S
GROUP BY ParliamentNumber